var aiv_images = null;
var aiv_comments = null;
var aiv_current = null;
var aiv_initialized = false;

function aiv_initialize() {
    aiv_images = $("aiv_images").value.split(",");
    aiv_comments = $("aiv_comments").value.split(",");
    aiv_current = $("aiv_initial").value * 1;
    aiv_initialized = true;
    
    aiv_preload();
}

function aiv_preload() {
    parent = $("aiv_images").parentNode;
    
    for (x = 0; x < aiv_images.length; x++) {
        img = document.createElement("img");
        img.style.display = "none";
        img.src = aiv_images[x];
    }
}

function aiv_advance(amount) {
    if (aiv_initialized) {
        if (aiv_current + amount > aiv_images.length - 1) aiv_goto(aiv_current + amount - aiv_images.length);
        else if (aiv_current + amount < 0) aiv_goto(aiv_current + amount + aiv_images.length);
        else aiv_goto(aiv_current + amount);
    }
}
function aiv_goto(index) {
    if (aiv_initialized && aiv_images[index]) {
        if (aiv_comments[index])
            $("aiv_comment_pane").innerHTML = aiv_comments[index];
            
        $("aiv_image").setAttribute("src",aiv_images[index]);
        $("indicator_" + aiv_current).setAttribute("class","indicator");
        $("indicator_" + index).setAttribute("class","active indicator");
        
        aiv_current = index;
    }
}